package com.example.arm.integration.lifecycle

import android.app.Activity
import androidx.lifecycle.*

/**
 *  author : yanghaozhang
 *  date : 2020/9/10 11:28
 *  description :
 */
open class ActivityDelegate(protected var mActivity: Activity?) : DefaultLifecycleObserver {

    init {
        if (mActivity is LifecycleOwner) {
            (mActivity as LifecycleOwner).lifecycle.addObserver(this)
        }
    }

    override fun onDestroy(owner: LifecycleOwner) {
        owner.lifecycle.removeObserver(this)
        onDestroyed(owner)
        mActivity = null
    }

    open fun onDestroyed(owner: LifecycleOwner) {

    }
}